package com.objectproject.main.service.subsystem;

import java.util.ArrayList;

import org.springframework.stereotype.Service;

import com.objectproject.main.enumeration.ValueType;
import com.objectproject.main.exception.RenderFailException;
import com.objectproject.main.model.MyObject;
import com.objectproject.main.model.MyProperty;
import com.objectproject.main.model.primitive.MyPrimitiveDate;
import com.objectproject.main.model.primitive.MyPrimitiveInteger;
import com.objectproject.main.model.primitive.MyPrimitiveReal;
import com.objectproject.main.model.primitive.MyPrimitiveText;
import com.objectproject.main.model.primitive.MyPrimitiveTime;

@Service
public class PrimitiveRenderer {
	
	//값을 html에 적절하도록 고정시켜버림
	public void renderValues(MyObject myObject) throws RenderFailException{
		if(myObject.getMyProperties() != null){
			for(MyProperty myProperty:myObject.getMyProperties()){
				renderValue(myProperty);
			}
		}
	}
	
	public void renderValues(ArrayList<MyProperty> myProperties) throws RenderFailException{
		for(MyProperty myProperty:myProperties){
			renderValue(myProperty);
		}
	}
	
	public void renderValue(MyProperty myProperty) throws RenderFailException{
		
		ValueType valueType = myProperty.getTypeOfValue();
		Object value = myProperty.getValue();
		
		if(myProperty.getValue() != null){
			if(valueType == ValueType.COLLECTION){
				
			}else if(valueType == ValueType.INTEGER){
				myProperty.setValue(((MyPrimitiveInteger)value).getStringValue());
			}else if(valueType == ValueType.REAL){
				myProperty.setValue(((MyPrimitiveReal)value).getStringValue());
			}else if(valueType == ValueType.TEXT){
				myProperty.setValue(((MyPrimitiveText)value).getValue().toString());
			}else if(valueType == ValueType.DATE){
				myProperty.setValue(((MyPrimitiveDate)value).getValue().toString());
			}else if(valueType == ValueType.TIME){
				myProperty.setValue(((MyPrimitiveTime)value).getValue().toString());
			}else if(valueType == ValueType.IMAGE){
				
			}else if(valueType == ValueType.SOUND){
				
			}else if(valueType == ValueType.LOCATION){
				
			}else if(valueType == ValueType.VIDEO){
				
			}else{
				throw new RenderFailException("지원하지 않는 값 타입 :" + valueType);
			}
		}
	}
}
